﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SpellCaster3.Forms
{
    public partial class ToolTipForm : Form
    {
        public static int PositionOffset = 16;
        private const int FrameDuration = 16;
        private const int FadeInTime = 500;
        private uint RequiredFrames { get { return (uint)(FadeInTime / FrameDuration); } }
        private double Step { get { return 1.0 / RequiredFrames; } }
        private bool _Instant;
        private IWin32Window _Owner;

        public ToolTipForm()
        {
            InitializeComponent();
            //Opacity = 0.0;
        }

        private void descriptionLabel_SizeChanged(object sender, EventArgs e)
        {
            Size = new Size(descriptionLabel.Width + 2, descriptionLabel.Height + 2);
        }

        private void ToolTipForm_VisibleChanged(object sender, EventArgs e)
        {
            if (!Visible)
                Location = new Point(-Size.Width, -Size.Height);
        }

        public string Description
        {
            set
            {
                descriptionLabel.Text = value;
            }
            get { return descriptionLabel.Text; }
        }

        public void StartShow(string text, IWin32Window owner, bool instant = false)
        {
            Description = text;
            _Instant = instant;
            _Owner = owner;

            if (showTimer.Enabled) showTimer.Stop();

            Location = new Point(Cursor.Position.X + PositionOffset, Cursor.Position.Y + PositionOffset);
            if (SpellCaster3.Properties.Settings.Default.DescriptionInitialShowDelay <= 0)
                showTimer.Interval = 1;
            else
                showTimer.Interval = SpellCaster3.Properties.Settings.Default.DescriptionInitialShowDelay;

            showTimer.Start();
        }

        public void StartHide()
        {
            showTimer.Stop();
            Visible = false;
        }

        private void showTimer_Tick(object sender, EventArgs e)
        {
            base.Show();
        }
    }
}
